/***
 * 文件上传
 *
 *
 * @param cname 传入的类名字
 * @returns {*} 返回json格式的数据
 * 返回结果例子：{code: 0, message: "文件上传成功", url: null, data: "\files\tmpFiles\201852611227637.jpg"}
 */
function uploadfile(cname) {
    var formData = new FormData();
    var id = 'input.' + cname;
    var tfile = $(id);
    console.log($(id).length);
    var url = '/file/upload';
    //计数器，如果选中的文件大于2，选择不同上传接口
    var count = 0;
    //检测标签的文件数量，并封装到formData
    for (var x = 0; x < tfile.length; x++) {
        var y = tfile[x].files.length;
        for (var i = 0; i < y; i++) {
            formData.append('file', tfile[x].files[i]);
        }
        count += y;
    }
    console.log(count);
    if (count > 1) {
        url = '/file/uploads';
    }
    var test = null;
    $.ajax({
        url: url,
        type: 'POST',
        cache: false,
        data: formData,
        async:false,
        processData: false,
        contentType: false
    }).done(function (res) {
        tfile.each(function () {
            $(this).val("");
            console.log("文件清空完成");
        });
        console.log(res);
        test = res;
        return res;
    }).fail(function (res) {
        console.log(res);
        test = res;
        return res;
    });
    return test;
}